/*
 * LDIR
 * 
 * LDIR, a GPS cartography application built for Let's Do It Romania eco 
 * campaign.
 * Copyright (C) 2010 Genera Software <office@generasoftware.com>
 * 
 * http://generasoftware.com/
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
#ifndef __IMAGEFADECONTROL_H
#define __IMAGEFADECONTROL_H

// USER INCLUDES
#include "events.h"
#include "StaticImageControl.h"

// FORWARDS
class CFadeProvider;
class MFadeControlState;

/**
 * Control that fades an image to the screen.
 */
class CImageFadeControl : public CStaticImageControl
{
public:
    /**
     * Defines the types of fading.
     */
    enum TFadeType
    {
        EFadeIn = 0x01,
        EFadeOut = 0x02
    };
    /**
     * EPOC two phased constructor.
     * @param aRect The coordinates to place the control to.
     * @param aFader The fade transition controller. If NULL, a new CFadeProvider is created.
     */
    static CImageFadeControl* NewL(const TRect& aRect, CFadeProvider* aFader);
    /**
     * EPOC two phased constructor. Leaves a copy on the Cleanup Stack.
     * @param aRect The coordinates to place the control to.
     * @param aFader The fade transition.
     */
    static CImageFadeControl* NewLC(const TRect& aRect, CFadeProvider* aFader);
    /**
     * Destructor.
     */
    virtual ~CImageFadeControl();

    /**
     * From CStaticImageControl, SetImage.
     */
    void SetImage(CFbsBitmap* aBitmap);
    /**
     * From CStaticImageControl, Image/
     */
    CFbsBitmap* Image() const;
    /**
     * Starts fading the picture.
     * @param aFadeType The type of fading to perform.
     */
    void StartFade(TInt aFadeType);
    /**
     * Gets access to the FadeCompleted event.
     */
    TEvent0<void> FadeCompleted;
    /**
     * Sets the amount of time to show the image between transitions.
     * @param aMicroSeconds The delay in microseconds.
     */
    void SetFadingDelay(TInt aMicroSeconds);
    /**
     * Retrieves the amount of time to show the image between transitions.
     */
    TInt FadingDelay() const;
    /**
     * Sets the time of the transition.
     * @param aSteps The time.
     */
    void SetTransitionTime(TUint aTransitionTime);
    /**
     * Draws a fading step. Handles the StepCompleted event in the CFadeProvider.
     */
    void HandleStepCompleted();
    /**
     * Handles the fade completed event. Forwards handling to current state.
     */
    void HandleFadeCompleted();

protected:
    /**
     * Default constructor.
     */
    CImageFadeControl();
    /**
     * EPOC second phase constructor.
     * @param aRect The coordinates to place the control to.
     * @param aFader The fade transition.
     */
    void ConstructL(const TRect& aRect, CFadeProvider* aFader);

    /**
     * Callback from delay timer.
     */
    static TInt DelayTimerCallback(TAny* aPtr);

private:
    /** @var iSourceBitmap The source bitmap to fade to screen.*/
    CFbsBitmap* iSourceBitmap;
    /** @var iFader The fade transition controller.*/
    CFadeProvider* iFader;
    /** @var iOwnsFader Specifies if the control owns the fader.*/
    TBool iOwnsFader;
    /** @var iFadeType The required fade type to perform.*/
    TInt iFadeType;
    /** @var iDelay The delay between transitions.*/
    TInt iDelay;
    TUint iTransitionTime;
    /** @var iDelayTimer The timer responsible for delay between transitions.*/
    CPeriodic* iDelayTimer;
};

#endif //__IMAGEFADECONTROL_H
